package com.sf.dlb.jpa.repository;

import com.sf.dlb.jpa.model.UserGradeBuyRecordInfo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 用户等级购买记录 Repository
 *
 * Created by jing.tan on 2018/5/21.
 */
@Repository
public interface UserGradeBuyRecordRepository extends JpaRepository<UserGradeBuyRecordInfo, Long> {
    /**
     * 根据查询最新记录-userId,limit
     * @param userId
     * @param delFlag
     * @return
     */
    @Query(value = "select * from user_grade_buy_record a where a.user_id=:userId and a.del_flag=:delFlag order by a.create_date desc LIMIT 0,1",nativeQuery = true)
    UserGradeBuyRecordInfo findByUserIdAndDelFlagLimitOne(@Param("userId") String userId, @Param("delFlag") String delFlag);
    /**
     * 根据id查询
     * @param id
     * @return
     */
    UserGradeBuyRecordInfo findById(Long id);
    /**
     * 根据userId查询
     * @param userId
     * @param delFlag
     * @return
     */
    List<UserGradeBuyRecordInfo> findByUserIdAndDelFlag(String userId, String delFlag);
}